<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Tables</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Tables' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">assertions</a></li><li><a href="index.html#7">Chapter 7: Other Gadgets</a></li><li><b>Tables</b></li></ul></div>
<p class="purpose">To manage and compile tables, which are two-dimensional arrays with associative look-up facilities provided at run-time.</p>

<ul class="toc"><li><a href="7-tbl.html#SP4">&#167;4. Traversing for tables</a></li><li><a href="7-tbl.html#SP6">&#167;6. Table basics</a></li><li><a href="7-tbl.html#SP13">&#167;13. Table creation</a></li><li><a href="7-tbl.html#SP20">&#167;20. Table stocking</a></li><li><a href="7-tbl.html#SP24">&#167;24. Completing tables</a></li><li><a href="7-tbl.html#SP25">&#167;25. Amending tables</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>This is how a table is stored. Note that the limit on columns per table
must not rise to 100 or beyond because that would break the system of table
column ID numbers: see <a href="../runtime-module/5-tbl.html" class="internal">Tables (in runtime)</a>.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax"> </span><span class="constant-syntax">99</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_no_text</span><span class="plain-syntax">; </span><span class="comment-syntax"> the table number (if any)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_name_text</span><span class="plain-syntax">; </span><span class="comment-syntax"> the table name (if any)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax"> *</span><span class="identifier-syntax">table_created_at</span><span class="plain-syntax">; </span><span class="comment-syntax"> where created in source</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">headline_fragment</span><span class="plain-syntax">; </span><span class="comment-syntax"> a pseudo-sentence formed by the heading line</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">blank_rows</span><span class="plain-syntax">; </span><span class="comment-syntax"> number of entirely blank rows to be appended (may be 0)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">blank_rows_for_each_text</span><span class="plain-syntax">; </span><span class="comment-syntax"> add one blank for each instance</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">blank_rows_text</span><span class="plain-syntax">; </span><span class="comment-syntax"> text of blank rows specification</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">fill_in_blanks</span><span class="plain-syntax">; </span><span class="comment-syntax"> if set, fill any blank entries with default values</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">first_column_by_definition</span><span class="plain-syntax">; </span><span class="comment-syntax"> if set, first column defines new value names</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">kind_defined_in_this_table</span><span class="plain-syntax">; </span><span class="comment-syntax"> ...of this kind</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">contains_property_values_at_run_time</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">where_used_to_define</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">preserve_row_order_at_run_time</span><span class="plain-syntax">; </span><span class="comment-syntax"> if set, don't sort this table</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">amendment_of</span><span class="plain-syntax">; </span><span class="comment-syntax"> if amendment of earlier table</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">has_been_amended</span><span class="plain-syntax">; </span><span class="comment-syntax"> if there exists an amendment of this</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">approximate_array_space_needed</span><span class="plain-syntax">; </span><span class="comment-syntax"> at run-time, in words</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">disable_block_constant_correction</span><span class="plain-syntax">; </span><span class="comment-syntax"> if set, don't translate block constant entries</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_columns</span><span class="plain-syntax">; </span><span class="comment-syntax"> must be at least 1</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table_column_usage</span><span class="plain-syntax"> </span><span class="identifier-syntax">columns</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">];</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_compilation_data</span><span class="plain-syntax"> </span><span class="identifier-syntax">compilation_data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">table</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure table is accessed in 3/nuor, 3/dbtr, 5/id, 5/idf, 5/adf, 5/tpf, 5/rf, 5/rcd, 6/rls, 6/rlb, 6/fao, 6/act, 7/tc, 7/eqt and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>For indexing purposes only:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax"> *</span><span class="identifier-syntax">next</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure table_contribution is accessed in 2/ptmn, 2/cs, 2/ps, 2/is, 3/dlr, 3/pr, 3/tr, 3/nuor, 3/uor, 3/tr2, 3/dbtr, 3/rpr, 3/nar, 3/nlpr, 3/nrr, 3/npr, 3/nvr, 3/nar2, 3/ldr, 4/rpt, 4/tc, 4/ass, 4/npa, 4/rk, 4/ass2, 4/imp, 5/id, 5/adf, 5/rcd, 6/rlb, 6/act, 7/eqt, 8/tcp, 8/abp, 8/cu and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>These are convenient during parsing.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax"> = -1;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> = -1;</span>
<span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Traversing for tables.</b>Tables of data are created in two passes through the source text:
the first finds their names and registers them with the parser, while
the second (much later) works out their columns and contents. At some
point we also try to find ambiguity problems which might bite us later on.
</p>

<p class="commentary">Here is that later one. By this point all of the constant values in Inform
exist, and so do all of the kinds, so we can now make sense of the kinds
of the columns and of what's in them; and we can check that this is all
consistent. This is called "stocking", and it comes in three phases:
see below.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::traverse_to_stock</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">phase</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="identifier-syntax">phase</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">3</span><span class="plain-syntax">; </span><span class="identifier-syntax">phase</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><a href="7-tbl.html#SP20" class="function-link"><span class="function-syntax">Tables::stock_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">phase</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Last and least: a traverse existing just to issue a problem message in a
case which Inform can often cope with, but which the experience of users
suggests is never a good idea.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::check_tables_for_kind_clashes</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="function-syntax">&lt;k-kind-articled&gt;(t-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">Kinds::Behaviour::is_subkind_of_object</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableCoincidesWithKind</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"The name %1 will have to be disallowed because '%2' is also the "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"name of a kind, or of the plural of a kind. (For instance, writing "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"'Table of Rooms' is disallowed - it could lead to great confusion.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Table basics.</b>The following makes a blank structure for a table, but it isn't valid until
some of these fields have been properly filled in.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="function-syntax">Tables::new_table_structure</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Tables::new_table_structure</span></span>:<br/><a href="7-tbl.html#SP18">&#167;18</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">headline_fragment</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Diagrams::new_UNPARSED_NOUN</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">fill_in_blanks</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">first_column_by_definition</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">kind_defined_in_this_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">where_used_to_define</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">contains_property_values_at_run_time</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">preserve_row_order_at_run_time</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">has_been_amended</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">approximate_array_space_needed</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">disable_block_constant_correction</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">compilation_data</span><span class="plain-syntax"> = </span><span class="identifier-syntax">RTTables::new_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="7-tbl.html#SP7" class="function-link"><span class="function-syntax">Tables::add_table_contribution</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>A little linked list of chunks of source contributing to the table:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::add_table_contribution</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Tables::add_table_contribution</span></span>:<br/><a href="7-tbl.html#SP6">&#167;6</a>, <a href="7-tbl.html#SP18_10">&#167;18.10</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">src</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax"> = </span><span class="identifier-syntax">src</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table_contribution</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ltc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ltc</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">ltc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">)) </span><span class="identifier-syntax">ltc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ltc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ltc</span><span class="plain-syntax">) </span><span class="identifier-syntax">ltc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tc</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>Logging:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::log</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Tables::log</span></span>:<br/>Assertions Module - <a href="1-am.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"{%n}"</span><span class="plain-syntax">, </span><span class="identifier-syntax">RTTables::identifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Dimensions:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::get_no_columns</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::get_no_rows</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">; </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax">=</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[0].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">; </span><span class="identifier-syntax">PN</span><span class="plain-syntax">; </span><span class="identifier-syntax">PN</span><span class="plain-syntax">=</span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">) </span><span class="identifier-syntax">c</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">c</span><span class="plain-syntax"> += </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="function-syntax">Tables::cells_in_ith_column</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no such table"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;0) || (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;=</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"column out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>Miscellaneous services:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::expand_block_constants</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">disable_block_constant_correction</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="function-syntax">Tables::kind_of_ith_column</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;0) || (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;=</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tcdt for column out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="7-tc.html#SP6" class="function-link"><span class="function-syntax">Tables::Columns::get_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>Oddball forms of naming:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="function-syntax">Tables::get_headline</span><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">headline_fragment</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>The author can demand with a "translates as" sentence that a given
table should have an identifier given to it which is accessible to Inter:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::translates</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Tables::translates</span></span>:<br/>Translation Requests - <a href="3-tr.html#SP9_1_2">&#167;9.1.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">p2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;s-constant-value&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Rvalues::to_table</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">RTTables::translate</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">p2</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Tried %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TranslatesNonTable</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"this is not the name of a table"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"so cannot be translated."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Table creation.</b>Tables can be new, when they appear in the source, or can be related to
already-existing ones with the same name:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_IS_NEW</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_IS_CONTINUED</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_IS_AMENDED</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_IS_REPLACED</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>Their headers can have three forms:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_HAS_ONLY_NUMBER</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_HAS_ONLY_NAME</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TABLE_HAS_NUMBER_AND_NAME</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>The source text declaration of tables is not easy to parse. Tabs are
significantly different from spaces or new-lines, for instance &mdash; so the
ordinary rules about white space are suspended. Tabs divide entries in a row;
new-lines divide rows in a paragraph; and the table is terminated by a
paragraph break.
</p>

<p class="commentary">If a table is declared as
</p>

<blockquote>
    <p>Table 12 - Chemical Elements</p>
</blockquote>

<p class="commentary">then it can be referred to elsewhere in the source either as "Table 12"
or as "Table of Chemical Elements", so both excerpts are registered
as meaningful. But it is legal to declare a table with only one of the
two forms in any case.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;table-header&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax"> ( </span><span class="identifier-syntax">continued</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax"> ( </span><span class="identifier-syntax">amended</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax"> ( </span><span class="identifier-syntax">replaced</span><span class="plain-syntax"> ) |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-new-name&gt;</span>

<span class="function-syntax">&lt;table-new-name&gt;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> ... - ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> ### |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15_1" class="paragraph-anchor"></a><b>&#167;15.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_TableMisnamed problem</span><span class="named-paragraph-number">15.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableMisnamed</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"this isn't allowed as the name of a Table"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"since a table is required either to have a number, or to be a table 'of' "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"something (or both). For example: 'Table 5', 'Table of Blue Meanies', and "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'Table 2 - Submarine Hues' are all allowed, but 'Table concerning "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Pepperland' is not."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">TABLE_HAS_ONLY_NAME</span><span class="plain-syntax">, - };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP15">&#167;15</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>The following is then used to register table names as constants. The idea
is that "Table 12 - Chemical Elements" will be registered both as Table 12
and as Table of Chemical Elements.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;table-names-construction&gt;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> ... |</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. </b>Optionally, tables can have a footer line specifying additional entirely
blank rows. In (b), the <span class="extract"><span class="extract-syntax">...</span></span> is eventually required to be a kind, but this
happens later on, since the bare bones of tables are parsed very early in
Inform's run, when kinds haven't yet been created.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;table-footer&gt;</span>
<span class="plain-syntax">    *** </span><span class="identifier-syntax">with</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;cardinal-number&gt;</span><span class="plain-syntax"> </span><span class="identifier-syntax">blank</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">/</span><span class="identifier-syntax">rows</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    *** </span><span class="identifier-syntax">with</span><span class="plain-syntax"> ... </span><span class="identifier-syntax">blank</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">/</span><span class="identifier-syntax">rows</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    *** </span><span class="identifier-syntax">with</span><span class="plain-syntax"> </span><span class="identifier-syntax">blank</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">/</span><span class="identifier-syntax">rows</span><span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> </span><span class="identifier-syntax">each</span><span class="plain-syntax">/</span><span class="identifier-syntax">every</span><span class="plain-syntax"> ...</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18" class="paragraph-anchor"></a><b>&#167;18. </b>So, here goes. We first identify the top line of the table declaration
(the "headline"), then set the current sentence to that, even though in
parse tree terms it's only a fragment of a sentence: this makes problem
messages about the headline much more readable. We extract the table's
name, number and connection to other tables, and count its rows. In some
cases, for example where we are continuing an existing table, we use the
new table structure only temporarily: we transfer its rows to the existing
table and then destroy the temporary one made here.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::create_table</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Tables::create_table</span></span>:<br/>Passes through Major Nodes - <a href="2-ptmn.html#SP3_1">&#167;3.1</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">PN</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">connection</span><span class="plain-syntax"> = </span><span class="constant-syntax">TABLE_IS_NEW</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., no connection with existing tables</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">HW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::up_to</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::last_word_of_formatted_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">HW</span><span class="plain-syntax">) == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_1" class="named-paragraph-link"><span class="named-paragraph">Reject this lexically malformed table declaration</span><span class="named-paragraph-number">18.1</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax"> = </span><a href="7-tbl.html#SP6" class="function-link"><span class="function-syntax">Tables::new_table_structure</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="identifier-syntax">HW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">headline_fragment</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_2" class="named-paragraph-link"><span class="named-paragraph">Parse the table's header for a name and/or number, and connection to other tables</span><span class="named-paragraph-number">18.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_3" class="named-paragraph-link"><span class="named-paragraph">Require the table name not to tread on some other value</span><span class="named-paragraph-number">18.3</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_4" class="named-paragraph-link"><span class="named-paragraph">Find the first existing table with the same name, if any</span><span class="named-paragraph-number">18.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connection</span><span class="plain-syntax"> != </span><span class="constant-syntax">TABLE_IS_NEW</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_5" class="named-paragraph-link"><span class="named-paragraph">Require the previous table to exist</span><span class="named-paragraph-number">18.5</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_6" class="named-paragraph-link"><span class="named-paragraph">Require the previous table not to exist</span><span class="named-paragraph-number">18.6</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connection</span><span class="plain-syntax"> == </span><span class="constant-syntax">TABLE_IS_NEW</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_7" class="named-paragraph-link"><span class="named-paragraph">Register the names of the new table</span><span class="named-paragraph-number">18.7</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Created: $B\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_8" class="named-paragraph-link"><span class="named-paragraph">Parse the table's footer for a number of blank rows</span><span class="named-paragraph-number">18.8</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_9" class="named-paragraph-link"><span class="named-paragraph">Count out the rows and columns in the new table</span><span class="named-paragraph-number">18.9</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connection</span><span class="plain-syntax"> != </span><span class="constant-syntax">TABLE_IS_NEW</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10" class="named-paragraph-link"><span class="named-paragraph">Act on the connection, possibly destroying the temporary table just made</span><span class="named-paragraph-number">18.10</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18_1" class="paragraph-anchor"></a><b>&#167;18.1. </b>Changes to the lexer mean that this shouldn't happen, but just in case:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Reject this lexically malformed table declaration</span><span class="named-paragraph-number">18.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">BelievedImpossible</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"this table does not strictly speaking start a paragraph"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"and I'm afraid we need to speak strictly here. Even a comment coming before "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"the start of the table is too much."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_2" class="paragraph-anchor"></a><b>&#167;18.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Parse the table's header for a name and/or number, and connection to other tables</span><span class="named-paragraph-number">18.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Parsing table headline %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">HW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-header&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">HW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">connection</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;nameforms&gt;&gt;</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_HAS_ONLY_NUMBER:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_HAS_ONLY_NAME:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_HAS_NUMBER_AND_NAME:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-new-name&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">24</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">24</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::length</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">24</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording_as_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording_as_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableNameTooLong</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"This table has been called %1, but that's just too much text. Tables "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"really don't need names longer than 20 words."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_3" class="paragraph-anchor"></a><b>&#167;18.3. </b>Practical experience showed that the following restriction was wise:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require the table name not to tread on some other value</span><span class="named-paragraph-number">18.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;s-type-expression-or-value&gt;(t-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording_as_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableNameAmbiguous</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"The table name %1 will have to be disallowed as it is text which "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"already has a meaning to Inform. For instance, creating the 'Table "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"of Seven' would be disallowed because of the possible confusion "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"with the number 'seven'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_4" class="paragraph-anchor"></a><b>&#167;18.4. </b>It's not as simple as it seems to decide when a new table headline refers
back to a table which already exists &mdash; there are several ways we could play
this. What we say is that if the new headline gives both name and number,
then both must match; if it gives name only, that must match; if it gives
number only, that must. Suppose that "Table 2 - Trees" already exists. Then:
</p>

<ul class="items"><li>(a) if "Table 2 - Shrubs" or "Table 3 - Trees" comes along, there's no match;
</li><li>(b) if "Table of Trees" comes along, that does match;
</li><li>(c) if "Table 2" comes along, so does that.
</li></ul>
<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="identifier-syntax">TABLE_NAMES_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">, </span><span class="identifier-syntax">t2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    ((</span><span class="identifier-syntax">t1</span><span class="plain-syntax"> != </span><span class="identifier-syntax">t2</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::match</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">t1</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)))</span>
<span class="definition-keyword">define</span> <span class="identifier-syntax">TABLE_NUMBERS_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">, </span><span class="identifier-syntax">t2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    ((</span><span class="identifier-syntax">t1</span><span class="plain-syntax"> != </span><span class="identifier-syntax">t2</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t1</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::match</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">, </span><span class="identifier-syntax">t1</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)))</span>
</pre>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Find the first existing table with the same name, if any</span><span class="named-paragraph-number">18.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">TABLE_NAMES_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">)) &amp;&amp; (</span><span class="identifier-syntax">TABLE_NUMBERS_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TABLE_NAMES_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">                    (!(</span><span class="identifier-syntax">TABLE_NUMBERS_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">))))</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TABLE_NUMBERS_MATCH</span><span class="plain-syntax">(</span><span class="identifier-syntax">t2</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_5" class="paragraph-anchor"></a><b>&#167;18.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require the previous table to exist</span><span class="named-paragraph-number">18.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableNotContinuation</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"It looks as if %1 is meant to be related to an existing table, "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"but I can't find one if it is. %P"</span>
<span class="plain-syntax">            </span><span class="string-syntax">"Perhaps you've put the new part before the original? The original "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"has to be earlier in the source text."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_6" class="paragraph-anchor"></a><b>&#167;18.6. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require the previous table not to exist</span><span class="named-paragraph-number">18.6</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">HW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableNameDuplicate</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"I can't create %1 because its name overlaps with one that already "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"exists: %2. %P"</span>
<span class="plain-syntax">            </span><span class="string-syntax">"It's possible to continue the existing one, if you just want to "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"add more rows, by writing '%3 (continued)' here."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_7" class="paragraph-anchor"></a><b>&#167;18.7. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Register the names of the new table</span><span class="named-paragraph-number">18.7</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Registering table by number: table %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">);</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">word_assemblage</span><span class="plain-syntax"> </span><span class="identifier-syntax">wa</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PreformUtilities::merge</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-names-construction&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WordAssemblages::from_wording</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_no_text</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">AW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">WordAssemblages::to_wording</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">wa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Nouns::new_proper_noun</span><span class="plain-syntax">(</span><span class="identifier-syntax">AW</span><span class="plain-syntax">, </span><span class="identifier-syntax">NEUTER_GENDER</span><span class="plain-syntax">, </span><span class="identifier-syntax">ADD_TO_LEXICON_NTOPT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TABLE_MC</span><span class="plain-syntax">, </span><span class="identifier-syntax">Rvalues::from_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">), </span><span class="identifier-syntax">Task::language_of_syntax</span><span class="plain-syntax">());</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Registering table by name: table of %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">);</span>

<span class="plain-syntax">        </span><span class="identifier-syntax">word_assemblage</span><span class="plain-syntax"> </span><span class="identifier-syntax">wa</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PreformUtilities::merge</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-names-construction&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WordAssemblages::from_wording</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_name_text</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">AW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">WordAssemblages::to_wording</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">wa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Nouns::new_proper_noun</span><span class="plain-syntax">(</span><span class="identifier-syntax">AW</span><span class="plain-syntax">, </span><span class="identifier-syntax">NEUTER_GENDER</span><span class="plain-syntax">, </span><span class="identifier-syntax">ADD_TO_LEXICON_NTOPT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TABLE_MC</span><span class="plain-syntax">, </span><span class="identifier-syntax">Rvalues::from_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">), </span><span class="identifier-syntax">Task::language_of_syntax</span><span class="plain-syntax">());</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_8" class="paragraph-anchor"></a><b>&#167;18.8. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Parse the table's footer for a number of blank rows</span><span class="named-paragraph-number">18.8</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;table-footer&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-footer&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;each&gt;&gt;</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE:</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-footer&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE:</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NOT_APPLICABLE:</span><span class="plain-syntax"> </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;table-footer&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_9" class="paragraph-anchor"></a><b>&#167;18.9. </b>Here's where we start building. The table's representation in the parse
tree is currently very unhelpful: it's just one enormous sentence node with
all the words in, headings and cells merged together. Instead of using this
we hang a list of parse nodes, one for each cell, as children of the entries
node for each column.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Count out the rows and columns in the new table</span><span class="named-paragraph-number">18.9</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">pos</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">HW</span><span class="plain-syntax">)+1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pos</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">Wordings::last_wn</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row_end</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::last_word_of_formatted_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::from</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">pos</span><span class="plain-syntax">), </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Row %d is %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_count</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_end</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">pos</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">row_end</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">cell_end</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Wordings::last_word_of_formatted_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_end</span><span class="plain-syntax">), </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Cell (%d, %d) is %W\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">row_count</span><span class="plain-syntax">, </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">, </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_end</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_9_1" class="named-paragraph-link"><span class="named-paragraph">This is a column-heading cell</span><span class="named-paragraph-number">18.9.1</span></a></span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_9_2" class="named-paragraph-link"><span class="named-paragraph">This is a data cell</span><span class="named-paragraph-number">18.9.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pos</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cell_end</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_9_3" class="named-paragraph-link"><span class="named-paragraph">Add implied blank data cells to fill out the row as needed</span><span class="named-paragraph-number">18.9.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">row_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">row_count</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">2</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableWithoutRows</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="string-syntax">"%1 has no rows."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_9_1" class="paragraph-anchor"></a><b>&#167;18.9.1. </b>See "Table Columns" for the actual column creation: note that this makes
a node in the parse tree representing the column's use within this table.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a column-heading cell</span><span class="named-paragraph-number">18.9.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">CW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_end</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">overflow</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Diagrams::new_UNPARSED_NOUN</span><span class="plain-syntax">(</span><span class="identifier-syntax">CW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">limit</span><span class="plain-syntax"> = </span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">limit</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableTooManyColumns</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">overflow</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"There are %4 columns in %1 already, and that's the absolute limit, "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"so the column %3 can't be added."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Creating col %d from '%W'\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">, </span><span class="identifier-syntax">CW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">] = </span><a href="7-tc.html#SP8" class="function-link"><span class="function-syntax">Tables::Columns::add_to_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CW</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">) </span><span class="comment-syntax"> i.e., no Problem occurred</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_9">&#167;18.9</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_9_2" class="paragraph-anchor"></a><b>&#167;18.9.2. </b>Each data cell becomes a node, and is added to the list under its column.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a data cell</span><span class="named-paragraph-number">18.9.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">CW</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Wordings::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_end</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Diagrams::new_PROPER_NOUN</span><span class="plain-syntax">(</span><span class="identifier-syntax">CW</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;(</span><span class="identifier-syntax">row_count</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">given_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1 rather than 0</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(5, &amp;(</span><span class="identifier-syntax">given_col</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableRowFull</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"In row %4 of the table %1, the entry %3 won't fit, because its row "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"is already full. (This entry would be in column %5 and the table has "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"only %6.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">SyntaxTree::graft</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col_count</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_9">&#167;18.9</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_9_3" class="paragraph-anchor"></a><b>&#167;18.9.3. </b>If a row finishes early, we pad it out with blanks.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Add implied blank data cells to fill out the row as needed</span><span class="named-paragraph-number">18.9.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col_count</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">) { </span><span class="comment-syntax"> which can only happen on data rows</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cell</span><span class="plain-syntax"> = </span><a href="7-tbl.html#SP19" class="function-link"><span class="function-syntax">Tables::empty_cell_node</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">SyntaxTree::graft</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col_count</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_9">&#167;18.9</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10" class="paragraph-anchor"></a><b>&#167;18.10. </b>All parsing is finished now.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Act on the connection, possibly destroying the temporary table just made</span><span class="named-paragraph-number">18.10</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">old_t</span><span class="plain-syntax"> = </span><span class="identifier-syntax">existing_table_with_same_name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="7-tbl.html#SP7" class="function-link"><span class="function-syntax">Tables::add_table_contribution</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">old_t</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">headline_fragment</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">], </span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_COLUMNS_PER_TABLE</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_1" class="named-paragraph-link"><span class="named-paragraph">Build the column correspondence tables</span><span class="named-paragraph-number">18.10.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connection</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_IS_CONTINUED:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2" class="named-paragraph-link"><span class="named-paragraph">Make the new part a continuation of the existing table</span><span class="named-paragraph-number">18.10.2</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_IS_AMENDED:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_4" class="named-paragraph-link"><span class="named-paragraph">Make the new part an amendment of the existing table</span><span class="named-paragraph-number">18.10.4</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_IS_REPLACED:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_3" class="named-paragraph-link"><span class="named-paragraph">Make the new part a replacement of the existing table</span><span class="named-paragraph-number">18.10.3</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"unknown form of table connection"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_1" class="paragraph-anchor"></a><b>&#167;18.10.1. </b>We assume that columns in the new and old tables will be partial permutations
of each other: for example the old might have columns "fish", "mammals", "birds"
(index <span class="extract"><span class="extract-syntax">j</span></span> running from 0 to 2) and the new "mammals", "reptiles", "fish",
"fungi" (index <span class="extract"><span class="extract-syntax">i</span></span> running from 0 to 3). We're going to store both the permutation
and its inverse, with the index <span class="extract"><span class="extract-syntax">-1</span></span> meaning that the column doesn't appear in
the other table at all. The result will be:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">old_to_new:</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, -1</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_to_old:</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">, -1, </span><span class="constant-syntax">0</span><span class="plain-syntax">, -1</span>
</pre>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Build the column correspondence tables</span><span class="named-paragraph-number">18.10.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++) </span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] = -1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = -1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax"> == </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">j</span><span class="plain-syntax">; </span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Column correspondence table:\n  old-&gt;new: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"%d (%W) "</span><span class="plain-syntax">, </span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">],</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"\n  new-&gt;old: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"%d (%W) "</span><span class="plain-syntax">, </span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">],</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10">&#167;18.10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_2" class="paragraph-anchor"></a><b>&#167;18.10.2. </b>We can carry out the continuation immediately, since it just means splicing
the new table's rows onto the ends of the old table's columns.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make the new part a continuation of the existing table</span><span class="named-paragraph-number">18.10.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2_2" class="named-paragraph-link"><span class="named-paragraph">Require that every column of the new table is also found in the old one</span><span class="named-paragraph-number">18.10.2.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2_1" class="named-paragraph-link"><span class="named-paragraph">Transfer blank rows of the new table to the old one</span><span class="named-paragraph-number">18.10.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row_count</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">SyntaxTree::graft</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">]].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">row_count</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) { </span><span class="comment-syntax"> from 1 to omit the column headings</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">blank</span><span class="plain-syntax"> = </span><a href="7-tbl.html#SP19" class="function-link"><span class="function-syntax">Tables::empty_cell_node</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">blank</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">SyntaxTree::graft</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">blank</span><span class="plain-syntax">, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10">&#167;18.10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_2_1" class="paragraph-anchor"></a><b>&#167;18.10.2.1. </b>It's a little awkward to work out what the policy is if the original table
wants a row for each man, and the continuation wants a row for each woman.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Transfer blank rows of the new table to the old one</span><span class="named-paragraph-number">18.10.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> += </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(4, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableContinuationContradicts</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"The table %1 says that it should have a blank row for each "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"%4, but the original %2 already says it has a blank for each "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"%3. It can only be specified once."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_2">&#167;18.10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_3" class="paragraph-anchor"></a><b>&#167;18.10.3. </b>And similarly for replacements...
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make the new part a replacement of the existing table</span><span class="named-paragraph-number">18.10.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_3_2" class="named-paragraph-link"><span class="named-paragraph">Require that every column of the old table is also found in the new one</span><span class="named-paragraph-number">18.10.3.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_3_1" class="named-paragraph-link"><span class="named-paragraph">Copy blank rows of the new table to the old one</span><span class="named-paragraph-number">18.10.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="comment-syntax"> and if this isn't true, we've issued a Problem already</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span>
<span class="plain-syntax">                = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">]].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] == -1)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">++] = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]; </span><span class="comment-syntax"> old table must have room</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10">&#167;18.10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_3_1" class="paragraph-anchor"></a><b>&#167;18.10.3.1. </b>...but this is easier:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Copy blank rows of the new table to the old one</span><span class="named-paragraph-number">18.10.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_3">&#167;18.10.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_4" class="paragraph-anchor"></a><b>&#167;18.10.4. </b>Amendments can't be done yet, because they depend on recognising values,
and it's far too early in Inform's run to recognise constants. So we must
postpone the work until later: note that we don't destroy the new table
structure in this case.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make the new part an amendment of the existing table</span><span class="named-paragraph-number">18.10.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_4_1" class="named-paragraph-link"><span class="named-paragraph">Require that the old and new tables have exactly matching columns</span><span class="named-paragraph-number">18.10.4.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax"> = </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">has_been_amended</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Amendment table created pro tem\n"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10">&#167;18.10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_2_2" class="paragraph-anchor"></a><b>&#167;18.10.2.2. </b>Here each new column must appear once in the old table, but the new
table doesn't have to cover everything in the old table. (Blanks are
used in continuation rows for columns not mentioned.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require that every column of the new table is also found in the old one</span><span class="named-paragraph-number">18.10.2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">missing</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] == -1)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">missing</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">missing</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"nto[%d] = %d, otn[%d] = %d\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">new_to_old</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">], </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">missing</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"a column"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"columns"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableContinuationAddsCols</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"The table %1 won't work as a continuation, because it contains "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"%3 not found in the original %2."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2_2_1" class="named-paragraph-link"><span class="named-paragraph">Display the old and new table column names</span><span class="named-paragraph-number">18.10.2.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_2">&#167;18.10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_3_2" class="paragraph-anchor"></a><b>&#167;18.10.3.2. </b>Here each old column must appear once in the new table, but the new
table is allowed to have extra columns. (This means the new table can
be "wider" than the old one.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require that every column of the old table is also found in the new one</span><span class="named-paragraph-number">18.10.3.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">, </span><span class="identifier-syntax">missing</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] == -1)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">missing</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">missing</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">missing</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"a column"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(3, </span><span class="string-syntax">"columns"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableReplacementMissesCols</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"The table %1 won't work as a replacement, because it's missing "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"%3 found in the original %2."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2_2_1" class="named-paragraph-link"><span class="named-paragraph">Display the old and new table column names</span><span class="named-paragraph-number">18.10.2.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_3">&#167;18.10.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_4_1" class="paragraph-anchor"></a><b>&#167;18.10.4.1. </b>We require this to be the identity permutation, i.e., exactly the same
columns and in the same order.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require that the old and new tables have exactly matching columns</span><span class="named-paragraph-number">18.10.4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">mismatch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax"> != </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">) </span><span class="identifier-syntax">mismatch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">old_to_new</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">] != </span><span class="identifier-syntax">j</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">mismatch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">mismatch</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">old_t</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableAmendmentMisfit</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"Columns in %1 do not exactly match the original %2. I can only "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"make changes to rows in an existing table if the amended versions "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"have the same columns and in the same order."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP18_10_2_2_1" class="named-paragraph-link"><span class="named-paragraph">Display the old and new table column names</span><span class="named-paragraph-number">18.10.2.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DESTROY</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_4">&#167;18.10.4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP18_10_2_2_1" class="paragraph-anchor"></a><b>&#167;18.10.2.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Display the old and new table column names</span><span class="named-paragraph-number">18.10.2.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_begin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="string-syntax">"****"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">"The old table has columns: "</span><span class="plain-syntax">); {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">j</span><span class="function-syntax">&lt;old_t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">j</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">", "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">"%+W"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span><span class="identifier-syntax">old_t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">j</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">". "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment_from_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_begin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="string-syntax">"****"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">"The new table has columns: "</span><span class="plain-syntax">); {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">", "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">"%+W"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">, </span><span class="string-syntax">"."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment_from_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEMP</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP18_10_2_2">&#167;18.10.2.2</a>, <a href="7-tbl.html#SP18_10_3_2">&#167;18.10.3.2</a> and <a href="7-tbl.html#SP18_10_4_1">&#167;18.10.4.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP19" class="paragraph-anchor"></a><b>&#167;19. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="function-syntax">Tables::empty_cell_node</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Tables::empty_cell_node</span></span>:<br/><a href="7-tbl.html#SP18_9_3">&#167;18.9.3</a>, <a href="7-tbl.html#SP18_10_2">&#167;18.10.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Diagrams::new_PROPER_NOUN</span><span class="plain-syntax">(</span><span class="identifier-syntax">EMPTY_WORDING</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP20" class="paragraph-anchor"></a><b>&#167;20. Table stocking.</b>See also the corresponding code in "Table Sections".
</p>

<p class="commentary">Note that the first column plays a special role in tables used to define new
constants, because it holds the names of things which don't exist yet &mdash; the
things to be defined. So we exempt it from the checking below.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::stock_table</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Tables::stock_table</span></span>:<br/><a href="7-tbl.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">phase</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Stocking $B (%d cols): phase %d\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">, </span><span class="identifier-syntax">phase</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">first_column_by_definition</span><span class="plain-syntax">) </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;t-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">table_column_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tcu</span><span class="plain-syntax"> = &amp;(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">phase</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">tcu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">kind_name_entries</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">tcu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actual_constant_entries</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">tcu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">observed_constant_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><a href="7-tc.html#SP13" class="function-link"><span class="function-syntax">Tables::Columns::check_explicit_headings</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">tcu</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">: {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">PN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PN</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="identifier-syntax">PN</span><span class="plain-syntax">; </span><span class="identifier-syntax">PN</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PN</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">PN</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                        </span><a href="7-tbl.html#SP23" class="function-link"><span class="function-syntax">Tables::stock_table_cell</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">PN</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">: </span><a href="7-tc.html#SP15" class="function-link"><span class="function-syntax">Tables::Columns::approve_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">tcu</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP21" class="paragraph-anchor"></a><b>&#167;21. </b>All of that is delegated to "Table Columns" except for the <span class="extract"><span class="extract-syntax">Tables::stock_table_cell</span></span>
routine, which comes next. It will parse the text of the entry in a cell
and act accordingly; the grammar returns one of the following:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">BLANK_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">SPEC_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">ACTION_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TOPIC_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">INSTANCE_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">5</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">KIND_TABLE_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">6</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">NAMED_CONSTANT_ENTRY</span><span class="plain-syntax"> </span><span class="constant-syntax">7</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">PROBLEMATIC_TABLE_ENTRY</span><span class="plain-syntax"> -1</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22" class="paragraph-anchor"></a><b>&#167;22. </b>Every cell of every table is required to match the following. Perhaps
unexpectedly, the syntax doesn't require each entry to be a valid Inform
constant; entries can also be blanks, or names of kinds (thus specifying the
kind of the table but not the contents), and there are special arrangements
for grammar to be understood (in "topic" columns) and for actions written as
constants.
</p>

<p class="commentary">Despite appearances, fully general type expressions (such as "open doors", or
"number of women") can't legally appear in table cells. The contents have
to be constants; the grammar lets more general text through only to let
us issue more contextual problem messages.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;table-cell&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-cell-blank&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;k-kind-articled&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-named-constant&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-global-variable&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-cell-value&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;list-of-double-quotes&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    ...</span>

<span class="function-syntax">&lt;table-cell-blank&gt;</span>
<span class="plain-syntax">    --</span>

<span class="function-syntax">&lt;table-cell-value&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">action</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;s-constant-action&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-constant-action&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">action</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;s-explicit-action&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-explicit-action&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;instance-of-non-object&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-type-expression&gt;</span>

<span class="function-syntax">&lt;list-of-double-quotes&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;quoted-text&gt;</span><span class="plain-syntax"> </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="function-syntax">&lt;list-of-double-quotes&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;quoted-text&gt;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22_1" class="paragraph-anchor"></a><b>&#167;22.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make anomalous entry for kind</span><span class="named-paragraph-number">22.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::from_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1]);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Node::set_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">KIND_TABLE_ENTRY</span><span class="plain-syntax">, </span><span class="identifier-syntax">new</span><span class="plain-syntax"> };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_2" class="paragraph-anchor"></a><b>&#167;22.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make anomalous entry for text to be understood</span><span class="named-paragraph-number">22.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::from_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Node::set_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">new</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">TOPIC_TABLE_ENTRY</span><span class="plain-syntax">, </span><span class="identifier-syntax">new</span><span class="plain-syntax"> };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_3" class="paragraph-anchor"></a><b>&#167;22.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_NonconstantActionInTable problem</span><span class="named-paragraph-number">22.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(5,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_NonconstantActionInTable</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"In %1, I'm reading the text %3 in column %4 (%5) of row %6, but this is "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"an action involving a variable, that is, a value that might vary in play. "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"%PThis often happens if the action mentions 'the player', for example, "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"because 'the player' is a variable. If 'the player' is the person "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"carrying out the action, simply leave those words out; if 'the player' "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"is involved in some other way, try using 'yourself' instead."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">PROBLEMATIC_TABLE_ENTRY</span><span class="plain-syntax">, - };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22">&#167;22</a> (twice).</li></ul>
<p class="commentary firstcommentary"><a id="SP22_4" class="paragraph-anchor"></a><b>&#167;22.4. </b>The message PM_TablePlayerEntry is so called because by far the commonest
case of this is people writing "player" as a constant value in a column of
people &mdash; it needs to be "yourself" instead, since "player" is a variable.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_TablePlayerEntry or C20TableVariableEntry problem</span><span class="named-paragraph-number">22.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">nonlocal_variable</span><span class="plain-syntax"> *</span><span class="identifier-syntax">q</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Lvalues::get_nonlocal_variable_if_any</span><span class="plain-syntax">(</span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1]);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">q</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no such variable"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inference_subject</span><span class="plain-syntax"> *</span><span class="identifier-syntax">infs</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NonlocalVariables::get_alias</span><span class="plain-syntax">(</span><span class="identifier-syntax">q</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">infs</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(5,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_subject</span><span class="plain-syntax">(7, </span><span class="identifier-syntax">infs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TablePlayerEntry</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"In %1, the entry %3 in column %4 (%5) of row %6 is the name of a value "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"which varies, not a constant, and can't be stored as a table entry. %P"</span>
<span class="plain-syntax">            </span><span class="string-syntax">"This variable is usually set to the constant value '%7', so you might "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"want to write that instead."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(5,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableVariableEntry</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"In %1, the entry %3 in column %4 (%5) of row %6 is the name of a value "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"which varies, not a constant, so it can't be stored as a table entry."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">PROBLEMATIC_TABLE_ENTRY</span><span class="plain-syntax">, - };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_5" class="paragraph-anchor"></a><b>&#167;22.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue PM_TableUnknownEntry problem</span><span class="named-paragraph-number">22.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP22_5_1" class="named-paragraph-link"><span class="named-paragraph">Actually issue PM_TableUnknownEntry problem</span><span class="named-paragraph-number">22.5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    ==&gt; { </span><span class="constant-syntax">PROBLEMATIC_TABLE_ENTRY</span><span class="plain-syntax">, - };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22">&#167;22</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP22_5_1" class="paragraph-anchor"></a><b>&#167;22.5.1. </b>(There are actually two ways this can happen, which is why it's set out like this.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Actually issue PM_TableUnknownEntry problem</span><span class="named-paragraph-number">22.5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(5,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableUnknownEntry</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"In %1, I'm reading the text %3 in column %4 (%5) of row %6, but I don't "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"know what this means. %PThis should usually be a value, like a number "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"or a piece of text, or a blank entry marker '--', but in some circumstances "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"it can also be an action (such as 'taking the box'), or a kind (such as "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"'a number') to show what sort of values will go into an otherwise blank "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"row."</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP22_5">&#167;22.5</a> and <a href="7-tbl.html#SP23_2">&#167;23.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP23" class="paragraph-anchor"></a><b>&#167;23. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::stock_table_cell</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Tables::stock_table_cell</span></span>:<br/><a href="7-tbl.html#SP20">&#167;20</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row_count</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">topic_exception</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table_cell_node</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax"> = </span><span class="identifier-syntax">row_count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP23_1" class="named-paragraph-link"><span class="named-paragraph">Parse the table cell and give it an evaluation as a noun</span><span class="named-paragraph-number">23.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">evaluation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Node::get_evaluation</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Cell evaluates to: $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">topic_exception</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP23_2" class="named-paragraph-link"><span class="named-paragraph">Require the cell to evaluate to an actual constant</span><span class="named-paragraph-number">23.2</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><a href="7-tc.html#SP14" class="function-link"><span class="function-syntax">Tables::Columns::note_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">, &amp;(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col_count</span><span class="plain-syntax">]), </span><span class="identifier-syntax">cell</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">), </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP23_1" class="paragraph-anchor"></a><b>&#167;23.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Parse the table cell and give it an evaluation as a noun</span><span class="named-paragraph-number">23.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="function-syntax">&lt;table-cell&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">BLANK_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">SPEC_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP1" class="function-link"><span class="function-syntax">Refiner::give_spec_to_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NAMED_CONSTANT_ENTRY:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">topic_exception</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP1" class="function-link"><span class="function-syntax">Refiner::give_spec_to_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">INSTANCE_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP1" class="function-link"><span class="function-syntax">Refiner::give_spec_to_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">KIND_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="7-tc.html#SP14" class="function-link"><span class="function-syntax">Tables::Columns::note_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">col_count</span><span class="plain-syntax">, &amp;(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col_count</span><span class="plain-syntax">]), </span><span class="identifier-syntax">cell</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">K</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">ACTION_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP1" class="function-link"><span class="function-syntax">Refiner::give_spec_to_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TOPIC_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP1" class="function-link"><span class="function-syntax">Refiner::give_spec_to_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">topic_exception</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PROBLEMATIC_TABLE_ENTRY:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP23">&#167;23</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP23_2" class="paragraph-anchor"></a><b>&#167;23.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Require the cell to evaluate to an actual constant</span><span class="named-paragraph-number">23.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Specifications::is_kind_like</span><span class="plain-syntax">(</span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Specifications::is_description</span><span class="plain-syntax">(</span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Evaluation is $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(4, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(5,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">table_being_examined</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">table_cell_col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">table_cell_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableDescriptionEntry</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"In %1, the entry %3 in column %4 (%5) of row %6 is a general description "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"of things with no definite value, and can't be stored as a table entry."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::is</span><span class="plain-syntax">(</span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">, </span><span class="identifier-syntax">CONSTANT_NT</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Evaluation is $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">evaluation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP22_5_1" class="named-paragraph-link"><span class="named-paragraph">Actually issue PM_TableUnknownEntry problem</span><span class="named-paragraph-number">22.5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP23">&#167;23</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP24" class="paragraph-anchor"></a><b>&#167;24. Completing tables.</b>Later on in Inform's run, just before compiling the tables, we call this:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::complete</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP24_1" class="named-paragraph-link"><span class="named-paragraph">Finally make any table amendments which have been called for</span><span class="named-paragraph-number">24.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP24_2" class="named-paragraph-link"><span class="named-paragraph">Create blank rows described textually, if they were</span><span class="named-paragraph-number">24.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP24_3" class="named-paragraph-link"><span class="named-paragraph">Create blank rows for each instance of a kind, if requested</span><span class="named-paragraph-number">24.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP24_1" class="paragraph-anchor"></a><b>&#167;24.1. </b>For the actual code, see below.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Finally make any table amendments which have been called for</span><span class="named-paragraph-number">24.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><a href="7-tbl.html#SP25" class="function-link"><span class="function-syntax">Tables::amend_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP24">&#167;24</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP24_2" class="paragraph-anchor"></a><b>&#167;24.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Create blank rows described textually, if they were</span><span class="named-paragraph-number">24.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;s-named-constant&gt;</span><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NonlocalVariables::substitute_constants</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Rvalues::to_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">N</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> = </span><span class="identifier-syntax">N</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(4, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableUnknownBlanks</span><span class="plain-syntax">),</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"%1 asked to have '%4' extra blank rows, but that would "</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"only make sense for a literal number like '15' or a "</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"name for a constant number. (The number must of course "</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"be 0 or more.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP24">&#167;24</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP24_3" class="paragraph-anchor"></a><b>&#167;24.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Create blank rows for each instance of a kind, if requested</span><span class="named-paragraph-number">24.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">amendment_of</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;k-kind&gt;(t-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows</span><span class="plain-syntax"> += </span><span class="identifier-syntax">Instances::count</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(4, </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">blank_rows_for_each_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">StandardProblems::table_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableKindlessBlanks</span><span class="plain-syntax">),</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"%1 asked to have extra blank rows for each '%4', but that "</span>
<span class="plain-syntax">                        </span><span class="string-syntax">"isn't a kind, so I can't see how many blank rows to make."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP24">&#167;24</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25" class="paragraph-anchor"></a><b>&#167;25. Amending tables.</b>Unlike continuations and replacements, table amendments depend on actual values
written into the cells, which means they can't be performed early in the run.
So for quite a long time two table structures exist: the "main table", the
actual one which will exist in play; and the "amendments" table, which is a
structure holding the amendment lines, but which won't actually exist
independently at run-time. The following routine is where the rows from the
amendments table are used to modify the main table, after which the amendments
table has no further use.
</p>

<p class="commentary">As might be expected, we work down the amendments table and apply them one
at a time:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::amend_table</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Tables::amend_table</span></span>:<br/><a href="7-tbl.html#SP24_1">&#167;24.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">main_table</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">amendments</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Amending table $B according to $B\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">, </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">leftmost_amend_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">amend_row</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">amendment_problem_opened</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">amend_row</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">leftmost_amend_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[0].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">leftmost_amend_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">amend_row</span><span class="plain-syntax">++, </span><span class="identifier-syntax">leftmost_amend_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">leftmost_amend_cell</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1" class="named-paragraph-link"><span class="named-paragraph">Apply the amendment in this row to the main table</span><span class="named-paragraph-number">25.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP25_1" class="paragraph-anchor"></a><b>&#167;25.1. </b>The following is not so obvious. The amendment row is intended to replace a
row in the main table, and we need to decide which one. Suppose the amendment
reads:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">62</span><span class="plain-syntax">   </span><span class="string-syntax">"lampstand"</span><span class="plain-syntax">   </span><span class="constant-syntax">10</span><span class="plain-syntax">:30 </span><span class="identifier-syntax">AM</span>
</pre>
<p class="commentary">If the main table has exactly one row with 62 in the first column, we choose
that; if it contains more than one, we look for rows which begin with
<span class="extract"><span class="extract-syntax">62</span></span> and then <span class="extract"><span class="extract-syntax">"lampstand"</span></span>; and so on. (Recall that amendment tables have
exactly the same columns as their originals, and in the same order.)
</p>

<p class="commentary">In the following, <span class="extract"><span class="extract-syntax">col</span></span> is the rightmost column used in the initial string
being tried: so when it's 0, we're just trying to match <span class="extract"><span class="extract-syntax">62</span></span>, when it's 1
we're trying to match <span class="extract"><span class="extract-syntax">62</span></span> and <span class="extract"><span class="extract-syntax">"lampstand"</span></span>; and so on. But of course each
such search is narrower than the one before, so we only need to look at the
rows which passed last time, and test their values in column <span class="extract"><span class="extract-syntax">col</span></span>.
</p>

<p class="commentary">In fact, we do this in reverse: we start with every row in the main table
marked as a possible match, and then exclude rows as they fail to match.
Eventually this should leave only a single row, and that's the winner.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Apply the amendment in this row to the main table</span><span class="named-paragraph-number">25.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">matches_in_last_round</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_1" class="named-paragraph-link"><span class="named-paragraph">Mark every row in the main table as a possible match</span><span class="named-paragraph-number">25.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">col</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">col</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_2" class="named-paragraph-link"><span class="named-paragraph">Set the amend-cell to this column's cell in the current amendment row</span><span class="named-paragraph-number">25.1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Annotations::read_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">only_row_left</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_3" class="named-paragraph-link"><span class="named-paragraph">Use the key value in the amend-cell to make an amendment</span><span class="named-paragraph-number">25.1.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">only_row_left</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><a href="7-tbl.html#SP26" class="function-link"><span class="function-syntax">Tables::splice_table_row</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">main_table</span><span class="plain-syntax">, </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">, </span><span class="identifier-syntax">only_row_left</span><span class="plain-syntax">, </span><span class="identifier-syntax">amend_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25">&#167;25</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_1" class="paragraph-anchor"></a><b>&#167;25.1.1. </b>We need one flag for each row in the main table; we do this with the "row
amendable" annotation for the cell nodes in the first column. (There's nothing
special about the first column, but it's guaranteed to exist, i.e., there is
always at least one column.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Mark every row in the main table as a possible match</span><span class="named-paragraph-number">25.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[0].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_amendable_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">matches_in_last_round</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1">&#167;25.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_2" class="paragraph-anchor"></a><b>&#167;25.1.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Set the amend-cell to this column's cell in the current amendment row</span><span class="named-paragraph-number">25.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">amend_row</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">++, </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">) ;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"columns in amendments aren't equal in length"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1">&#167;25.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_3" class="paragraph-anchor"></a><b>&#167;25.1.3. </b>When we get here, then, we look at the key value in the amend-cell: suppose
this is the number 17. If there's no row in the main table having 17 in this
column, we're stuck. But if there are two or more, we allow the loop to move
us along to the next column, hoping that the key value there will find a
unique match. If we're in the last column and there are still multiple
possibilities, the amendment row must be identical to more than one row
of the main table &mdash; in this case the amendment will have no effect, but
put another way, it can do no harm.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Use the key value in the amend-cell to make an amendment</span><span class="named-paragraph-number">25.1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">amend_key</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Node::get_evaluation</span><span class="plain-syntax">(</span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">TABLES</span><span class="plain-syntax">, </span><span class="string-syntax">"Amend row %d, col %d, key $P: $T\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">amend_row</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">amend_key</span><span class="plain-syntax">, </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::is</span><span class="plain-syntax">(</span><span class="identifier-syntax">amend_key</span><span class="plain-syntax">, </span><span class="identifier-syntax">CONSTANT_NT</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad key in amendments table"</span><span class="plain-syntax">); </span><span class="comment-syntax"> code above should make this impossible</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">matches</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_3_1" class="named-paragraph-link"><span class="named-paragraph">Find the number of possible-match rows in the main table with this key value in the same column</span><span class="named-paragraph-number">25.1.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">matches</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_3_2" class="named-paragraph-link"><span class="named-paragraph">Issue problem to say that no row in the main table matches</span><span class="named-paragraph-number">25.1.3.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">matches</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="comment-syntax"> i.e., if we haven't reached the final column</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">only_row_left</span><span class="plain-syntax"> = -1; </span><span class="comment-syntax"> because there's no single row left</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">matches_in_last_round</span><span class="plain-syntax"> = </span><span class="identifier-syntax">matches</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1">&#167;25.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_3_1" class="paragraph-anchor"></a><b>&#167;25.1.3.1. </b>The loop below and its inner conditional look pretty forbidding, but they
come down to this: loop through each row of the main table which is still a
possible match.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Find the number of possible-match rows in the main table with this key value in the same column</span><span class="named-paragraph-number">25.1.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">main_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">main_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[0].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">main_cell</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">row</span><span class="plain-syntax">++,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">main_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">main_cell</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax"> = </span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">main_value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Node::get_evaluation</span><span class="plain-syntax">(</span><span class="identifier-syntax">main_cell</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Annotations::read_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_amendable_ANNOT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_3_1_1" class="named-paragraph-link"><span class="named-paragraph">See if this possible-match row has the right key value in the new column</span><span class="named-paragraph-number">25.1.3.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1_3">&#167;25.1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_3_1_1" class="paragraph-anchor"></a><b>&#167;25.1.3.1.1. </b>We not only record the result if there's a match; we kick the row out of the
possible-match set if there isn't.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">See if this possible-match row has the right key value in the new column</span><span class="named-paragraph-number">25.1.3.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Key in row %d is $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">, </span><span class="identifier-syntax">main_value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Node::is</span><span class="plain-syntax">(</span><span class="identifier-syntax">main_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">CONSTANT_NT</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Rvalues::compare_CONSTANT</span><span class="plain-syntax">(</span><span class="identifier-syntax">amend_key</span><span class="plain-syntax">, </span><span class="identifier-syntax">main_value</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">matches</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">only_row_left</span><span class="plain-syntax"> = </span><span class="identifier-syntax">row</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">leftmost_cell</span><span class="plain-syntax">, </span><span class="identifier-syntax">row_amendable_ANNOT</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1_3_1">&#167;25.1.3.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_3_2" class="paragraph-anchor"></a><b>&#167;25.1.3.2. </b>That just leaves the problem message, a very subtle one which took a long
time to find a clear wording for:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue problem to say that no row in the main table matches</span><span class="named-paragraph-number">25.1.3.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="7-tbl.html#SP25_1_3_2_1" class="named-paragraph-link"><span class="named-paragraph">Begin an amendment problem message</span><span class="named-paragraph-number">25.1.3.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">col</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax"> i.e., counting from 1, not 0</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(1, &amp;</span><span class="identifier-syntax">amend_row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(2, &amp;</span><span class="identifier-syntax">quoted_col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">amend_cell</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(4,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Nouns::nominative_singular</span><span class="plain-syntax">(</span><span class="identifier-syntax">main_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">col</span><span class="plain-syntax">].</span><span class="element-syntax">column_identity</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(5, </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::quote_number</span><span class="plain-syntax">(6, &amp;</span><span class="identifier-syntax">matches_in_last_round</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">matches_in_last_round</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">2</span><span class="plain-syntax">) </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(7, </span><span class="string-syntax">"any"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">Problems::quote_text</span><span class="plain-syntax">(7, </span><span class="string-syntax">"either"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_begin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="string-syntax">"****"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"(Amendment %1). I can't match this to any row - there's nothing with "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"an entry of %3 in the lefthand column (%4)."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="string-syntax">"(Amendment %1). I can't decide which row this should replace. "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"It matches %6 rows until I get up to column %2 (%4), but then "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"it reads %3, which is different from %7 of them."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">break</span><span class="plain-syntax">; </span><span class="comment-syntax"> to move on to the next row in the amendments</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1_3">&#167;25.1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP25_1_3_2_1" class="paragraph-anchor"></a><b>&#167;25.1.3.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Begin an amendment problem message</span><span class="named-paragraph-number">25.1.3.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">amendment_problem_opened</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">amendment_problem_opened</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax"> = </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">table_created_at</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">source_table</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">main_table</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_table</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">amendments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableAmendmentMismatch</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"I'm currently trying to amend rows in %1 according to the instructions "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"in %2. To do that, I have to match each amendment row in turn, which "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"I do by trying to match up entries in the leftmost column(s)."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_begin</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="string-syntax">"****"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span><span class="string-syntax">"But I ran into problems:"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="7-tbl.html#SP25_1_3_2">&#167;25.1.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP26" class="paragraph-anchor"></a><b>&#167;26. </b>And, of course, the actual splicing of the amendment row in place of the
original:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::splice_table_row</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Tables::splice_table_row</span></span>:<br/><a href="7-tbl.html#SP25_1">&#167;25.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">table_to</span><span class="plain-syntax">, </span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">table_from</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row_to</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row_from</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;table_to-&gt;</span><span class="element-syntax">no_columns</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cell_to</span><span class="plain-syntax">, *</span><span class="identifier-syntax">cell_from</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">cell_to</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">row_to</span><span class="plain-syntax">); </span><span class="identifier-syntax">cell_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cell_to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">++) ;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_from</span><span class="plain-syntax"> = </span><span class="identifier-syntax">table_from</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">columns</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">].</span><span class="element-syntax">entries</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">down</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">cell_from</span><span class="plain-syntax"> &amp;&amp; (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">row_from</span><span class="plain-syntax">); </span><span class="identifier-syntax">cell_from</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cell_from</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">next</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">++) ;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">cell_to</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">cell_from</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><a href="4-rpt.html#SP3" class="function-link"><span class="function-syntax">Refiner::copy_noun_details</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">cell_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">cell_from</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Annotations::write_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Annotations::read_int</span><span class="plain-syntax">(</span><span class="identifier-syntax">cell_from</span><span class="plain-syntax">, </span><span class="identifier-syntax">table_cell_unspecified_ANNOT</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad table row splice"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP27" class="paragraph-anchor"></a><b>&#167;27. </b>This is called when a table is being asked to define objects (or kinds).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Tables::use_to_define</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Tables::use_to_define</span></span>:<br/>Define by Table Requests - <a href="3-dbtr.html#SP4_1_1">&#167;4.1.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">t</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">defining_objects</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">where</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no table"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">defining_objects</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">contains_property_values_at_run_time</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">fill_in_blanks</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">preserve_row_order_at_run_time</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">disable_block_constant_correction</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">has_been_amended</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">defining_objects</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_TableCantDefineAndAmend</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="string-syntax">"you can't use 'defined by' to define objects using a table "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"which is amended by another table"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"since that could too easily lead to ambiguities about what "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"the property values are."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">first_column_by_definition</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">t</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">where_used_to_define</span><span class="plain-syntax"> = </span><span class="identifier-syntax">where</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="7-tc.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-am.html">1</a></li><li class="progresschapter"><a href="2-bv.html">2</a></li><li class="progresschapter"><a href="3-dlr.html">3</a></li><li class="progresschapter"><a href="4-nr.html">4</a></li><li class="progresschapter"><a href="5-id.html">5</a></li><li class="progresschapter"><a href="6-rls.html">6</a></li><li class="progresscurrentchapter">7</li><li class="progresssection"><a href="7-tc.html">tc</a></li><li class="progresscurrent">tbl</li><li class="progresssection"><a href="7-eqt.html">eqt</a></li><li class="progresschapter"><a href="8-kpr.html">8</a></li><li class="progressnext"><a href="7-eqt.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

